<!-- START OF FUNCTIONS -->

<?php

function buildClientArr($arr){
	if (!$arr)
		return null;
	foreach ($arr as $key) {
		$res[$key['Company']['id']] = $key['Company']['name']; 
	}
	return $res;
}

?>

<script type="text/javascript" charset="utf-8">
	function toggleLayer( whichLayer, show )
	{
	  var elem, vis;
	  if( 	document.getElementById ) // this is the way the standards work
	    elem = document.getElementById( whichLayer );
	  else if( document.all ) // this is the way old msie versions work
	      elem = document.all[whichLayer];
	  else if( document.layers ) // this is the way nn4 works
	    elem = document.layers[whichLayer];
	  vis = elem.style;
		if (show) {
			vis.display = 'block';
		} else {
			vis.display = 'none';
		}
	}
</script>

<!-- END OF FUNCTIONS -->

<div id="add_form" class="largebloc2">
	<h2><?php __('add_user'); ?></h2>
	<br />
		<form action="add" enctype="multipart/form-data" method="post">
			<?php echo $form->input('User.lastname', array('error'=>'Please supply a lastname for this user.', 'label'=>__('last_name', true))); ?>
			<?php echo $form->input('User.firstname', array('error'=>'Please supply a firstname for this user.', 'label'=>__('first_name', true)));?>
			<?php echo $form->input('User.login', array('error'=>'Please supply a login for this user.', 'label'=>__('login', true)));?>
			<?php echo $form->label(__('company', true)); ?>
			<?php echo $form->select('User.company_id', buildClientArr($clientList), null,
						array('id'=>'ClientList', 'style'=>'width:150px;'),
						$showEmpty = __('nonee', true)); ?>
			<?php echo $form->error('company_id', 'Please select a company.'); ?>
			<?php echo $form->input('User.mail', array('label'=>__('mail', true))); ?>
			<?php echo $form->input('User.mobile', array('label'=>__('mobile_phone', true))); ?>
			<?php echo $form->input('User.phone', array('label'=>__('phone', true))); ?>
            		<?php echo "Photo ".$form->file('User.photo'); ?><br \>
			<?php __('generate_password') ?>
			<input type="radio" name="data[User][pass]" id="pass_oui" id="UserPass" value="oui" checked="checked" onclick="javascript:toggleLayer('password', false);" /><?php __('yes') ?><input type="radio" name="data[User][pass]" id="pass_non" id="UserPass" value="non" onclick="javascript:toggleLayer('password', true);" /><?php __('no') ?>
			<div id="password" style="display:none;">
				<?php echo $form->input('User.password', array('type'=>'password')); ?>
				<?php echo $form->input('User.password(confirm)', array('type'=>'password')); ?>
			</div>
			<p><input type="submit" value="<?php echo __('validate', true); ?>">&nbsp;<?php echo $html->link(__('cancel', true), ''); ?></p>
		<?php echo $form->end(); ?>
</div>